<?php


//http://v.qq.com/cover/3/3x8byn5eutf5dzp.html?vid=8KBLZGwuSF5
//$url = 'http://v.youku.com/v_show/id_XMjI4MDM4NDc2.html';
//$videoInfo = MbVideo::getVideoInfo($url);
//var_export($videoInfo);
//exit;

$uin = 2541521557;
$password = 'abc741';
$uin = 616207795;
$password = 'D8BB64D01E23EDF63B2B3CB7707C051E';
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 FirePHP/0.5';

$cookieDir = $app_data.'cookie/';
$cookieFile = $cookieDir.'qq.txt';
if (!is_dir($cookieDir)) {
	mkdir($cookieDir, 0777, true);
}
if (!is_file($cookieFile)) {
	file_put_contents($cookieFile, '');
}


$qq_verify = getQQVerify();
if (!$qq_verify) {
	var_dump($qq_verify);
	exit;
}
$password = preprocess($password, $qq_verify);

$url = 'http://ptlogin2.qq.com/check?uin=1103588275&appid=&r=0.03308127173597275';
$url = 'http://ptlogin2.qq.com/login?u=@' . $uin 
		.'&p=' . $password . '&verifycode=' . $qq_verify 
		.'&aid=46000101&u1=http://t.qq.com&h=1&from_ui=1&fp=loginerroralert';
//$url = 'http://ptlogin2.qq.com/login?u=616207795'
//		.'&p=A8EF776A8D69458BFB18DE800FA76FA0&verifycode=azww'
//		.'&aid=46000101&u1=http://t.qq.com&h=1&from_ui=1&fp=loginerroralert';
echo "\n\n";
echo $url, "\n\n";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$content = curl_exec($ch);
curl_close($ch);
echo $content;

//$ch = curl_init('http://t.qq.com/');
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_TIMEOUT, 60);
//curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
//curl_setopt($ch, CURLOPT_HEADER, true);
//curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
//curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
//$content = curl_exec($ch);
//curl_close($ch);
//echo $content;





function getQQVerify()
{
	global $uin, $userAgent, $cookieDir, $cookieFile;
//	static $times = 0;
//	if ($times > 10) return false;
	$url = 'http://ptlogin2.qq.com/check?uin=@'.$uin.'&appid=1002101&r=0.018001051743962604';
	$url = 'http://ptlogin2.qq.com/check?uin=616207795&appid=1003903&r=0.19382607359715964';
	echo $url;
	echo "\n\n";
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_TIMEOUT, 60);
	curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
	curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
	//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
	$content = curl_exec($ch);
	curl_close($ch);
	echo $content;
	echo "\n";
	preg_match("~ptui_checkVC\('([\d]+)','([^']*)'\)~", $content, $m);
	if ($m[1] != 0) {
		return '';
//		$times++;
//		getQQVerify();
	} else {
		var_export($m);
		return $m[2];
	}
//	$times = 0;
}













function preprocess($password,$verifycode) {
//	return strtoupper(md5(md5_3($password).strtoupper($verifycode)));
//	return md5(md5_3($password).$verifycode);
	return md5($password.$verifycode);
}
function md5_3($str) {
	return strtoupper(md5(md5(md5($str,true),true)));
}








